package com.itheima.thread.security.dem03;

import java.util.concurrent.locks.ReentrantLock;

public class SellTicket implements Runnable {

    private static int tickets = 10;
    private Object object = new Object();

    @Override
    public void run() {
        while (true){
            synchronized (object) {
                if (tickets > 0) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "正在出售第" + tickets + "张票");
                    tickets-- ;
                }
            }
        }
    }
}
